/*
 * @Copyright: 2017 www.yyfax.com Inc. All rights reserved.
 */
package com.yyfax.pay.order.model.to;

import java.io.Serializable;

import javax.validation.constraints.Min;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotBlank;

import com.yyfax.commons.json.FastJsonUtil;
import com.yyfax.pay.common.enums.PaymentEnum;
import com.yyfax.pay.common.exception.PayExceptionCode;

/**
 * 代付下单参数
 * 
 * @author jiangmy
 * @date 2017-04-11 13:56:44
 * @since v1.0.0
 */
@SuppressWarnings("serial")
public class PayoutOrderParams implements Serializable {
	@NotBlank(message = "serverIp不能为空")
	private String serverIp;

	@NotBlank(message = "userId不能为空")
	private String userId; // 商户用户ID

	@NotBlank(message = "orderId不能为空")
	private String orderId; // 商户订单号

	@NotBlank(message = "orderTime不能为空")
	private String orderTime; // 订单时间

	private String expireTime; // 过期时间

	@NotBlank(message = "paymentCode不能为空")
	private String paymentCode; // 支付通道编号

	@NotBlank(message = "payeeCardNo不能为空")
	private String payeeCardNo; // 收款

	@NotBlank(message = "payeeName不能为空")
	private String payeeName;

	@Min(value = 1, message = "amount不能小于1")
	private long amount; // 金额

	// 退票通知地址
	private String refundUrl;

	public String getServerIp() {
		return serverIp;
	}

	public void setServerIp(String serverIp) {
		this.serverIp = serverIp;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public String getOrderTime() {
		return orderTime;
	}

	public void setOrderTime(String orderTime) {
		this.orderTime = orderTime;
	}

	public String getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(String expireTime) {
		this.expireTime = expireTime;
	}

	public String getPaymentCode() {
		return paymentCode;
	}

	public void setPaymentCode(String paymentCode) {
		this.paymentCode = paymentCode;
	}

	public String getPayeeCardNo() {
		return payeeCardNo;
	}

	public void setPayeeCardNo(String payeeCardNo) {
		this.payeeCardNo = payeeCardNo;
	}

	public String getPayeeName() {
		return payeeName;
	}

	public void setPayeeName(String payeeName) {
		this.payeeName = payeeName;
	}

	public long getAmount() {
		return amount;
	}

	public void setAmount(long amount) {
		this.amount = amount;
	}

	public String getRefundUrl() {
		return refundUrl;
	}

	public void setRefundUrl(String refundUrl) {
		this.refundUrl = refundUrl;
	}

	/**
	 * 业务参数校验
	 * 
	 * @author buyi
	 * @date 2018-05-25 10:55:37
	 * @since v2.1.5
	 */
	public void validate() {
		if (PaymentEnum.fromValue(this.paymentCode) == null) {
			throw PayExceptionCode.ERROR_ILL_PARAMETER.expMsg("paymentCode非法");
		}

		// 校验，如果是通联代付，则退票地址不能为空
		if (PaymentEnum.ALL_IN_PAY.isValue(this.paymentCode) && StringUtils.isBlank(refundUrl)) {
			throw PayExceptionCode.ERROR_ILL_PARAMETER.expMsg("refundUrl不能为空");
		}
	}

	@Override
	public String toString() {
		return FastJsonUtil.toJson(this);
	}
}
